<?php
namespace App\DAO;

use Swoole\Async\Redis;
use Swoole\Record;

class UserLoginDAO extends BaseDAO
{
    const CACHE_LOGIN_TOKEN = 'logintoken#';
    const CACHE_LOGIN_UID = 'loginuid#';
    function getone()
    {
        $r = $this->get(10000,'user_id') ;
        $r->attach(new \App\Observer\ModelUpdate());
    }

    function isExist($openid)
    {

    }
    function  getUserIdbyOpenid($openid)
    {
         return $this->get($openid,'open_id');
    }
    function  getUserIdbyPeerID($peerid)
    {
        $this->get($peerid,'user_identifer');
    }
    function setUserLoginToCacheByToken($token,$userInfo)
    {
        return \Swoole::getInstance()->redis->hMset(self::CACHE_LOGIN_TOKEN.$token,$userInfo);
    }
    function getUserLoginFromCacheByToken($token)
    {
        return \Swoole::getInstance()->redis->hGetAll(self::CACHE_LOGIN_TOKEN.$token);
    }
    function setUserLoginToCacheByUid($userid,$userInfo)
    {
        return \Swoole::getInstance()->redis->hMset(self::CACHE_LOGIN_UID.$userid,$userInfo);
    }
    function getUserLoginFromCacheByUid($userid)
    {
        //var_dump(self::CACHE_LOGIN_UID.$userid);
        return \Swoole::getInstance()->redis->hGetAll(self::CACHE_LOGIN_UID.$userid);
    }
    function  updateUserIdTokenbyUserid($userid,$accesss_token)
    {

        return true;
    }


}
